package id.mankel.commons.mybatis;

import java.util.Arrays;

import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.LOWER_UNDERSCORE;

/**
 * For the column and property mapping.
 */
public class ResultMapper {

    private final String column;
    private final String property;

    public ResultMapper(String column, String property) {
        this.column = column;
        this.property = property;
    }

    public String getColumn() {
        return null == this.column ? LOWER_CAMEL.to(LOWER_UNDERSCORE, this.property) : this.column;
    }

    public String getProperty() {
        return null == this.property ? LOWER_UNDERSCORE.to(LOWER_CAMEL, this.column) : this.property;
    }

    public static ResultMapper column(String column) {
        return new ResultMapper(column, null);
    }

//    public static ResultMapper property(String property) {
//        return new ResultMapper(null, property);
//    }

    public static ResultMapper[] columns(String... columns) {
        return Arrays.stream(columns).map(ResultMapper::column).toArray(ResultMapper[]::new);
    }

}
